var routes = require('./routes/routes');
var authRoutes = require('./routes/authRoutes');
var gameRoutes = require('./routes/gameRoutes');
var ensureAuthenticated = authRoutes.ensureAuthenticated;
var ensureLoggedIn = require('connect-ensure-login').ensureLoggedIn;
var passport = require('passport');

function route(app, models, io) {
  routes.setModels(models);
  routes.setIo(io);
  app.get('/', ensureLoggedIn('/login'), routes.index);
  app.get('/auth/google', authRoutes.authenticateGoogle);
  app.get('/auth/google/oauth2callback', authRoutes.authenticateGoogleCallback);
  app.get('/login', routes.login);
  app.get('/logout', ensureLoggedIn('/login'), routes.logout);
  app.get('/playGame', ensureLoggedIn('/login'), gameRoutes.playGame);
  app.get('/joinGame', ensureLoggedIn('/login'), gameRoutes.joinGame);
  app.post('/login', passport.authenticate('local', { successReturnToOrRedirect: '/', failureRedirect: '/login' }));
  app.post('/createGame', ensureLoggedIn('/login'), gameRoutes.createGame);
  app.post('/queryGames', ensureLoggedIn('/login'), routes.queryGames);
  app.post('/sendChatMessage', ensureLoggedIn('/login'), gameRoutes.sendChatMessage);
  app.post('/sendPlay', ensureLoggedIn('/login'), gameRoutes.sendPlay);
  app.post('/getCards', ensureLoggedIn('/login'), gameRoutes.getCards);
}

exports.route = route;